package asynchronous;

import java.util.concurrent.ArrayBlockingQueue;

public class NacosPublish {
    public static ArrayBlockingQueue<Message> queue = new ArrayBlockingQueue<Message>(100);
    public void process() throws InterruptedException {
        while (true){
            Message message = queue.take();
            System.out.println(message);
        }
    }
    public boolean offer(Message message){
       return queue.offer(message);
    }

    public static void main(String[] args) throws InterruptedException {
        NacosPublish nacosPublish = new NacosPublish();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    nacosPublish.process();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        Thread.sleep(1000);
        nacosPublish.offer(new Message(1,"123456"));
        Thread.sleep(1000);
        nacosPublish.offer(new Message(2,"1236"));
    }
}
